#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
    int a=0,b=1;
    char c='\0';
    while(c<'0' || c>'9')
    {
        if(c=='-')
        {
            b*=-1;
        }
        c=getchar();
    }
    while(c>='0' && c<='9')
    {
        a=(a<<3)+(a<<1)+(c-'0');
        c=getchar();
    }
    return a*b;
}

const int MAXN=200005;
int dp[MAXN][2],a[MAXN];
set<int>SET;
stack<int>X,Y;

int dfs(int i,int n)
{
    if(i>n)
    {
        return 0;
    }
    int ans1=0,ans2=0;

    //cout<<X.top()<<"------"<<endl;

    if(!X.empty())
    {
        if(a[i]==X.top())
        {
            ans1+=a[i];
        }
    }
    X.push(a[i]);
    ans1+=dfs(i+1,n);
    X.pop();

    if(!Y.empty())
    {
        if(a[i]==Y.top())
        {
            ans2+=a[i];
        }
    }

    Y.push(a[i]);
    ans2+=dfs(i+1,n);
    Y.pop();

    //printf("%lld:%lld(%lld),%lld(%lld)",i,X.top(),ans1,Y.top,ans2);

    return max(ans1,ans2);
}

signed main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T;
    cin>>T;
    for(int TT=1;TT<=T;TT++)
    {
        int n;
        n=read();
        //cin>>n;
        for(int i=1;i<=n;i++)
        {
            a[i]=read();
            //cout<<a[i]<<' ';
            SET.insert(a[i]);
        }
        //cout<<endl<<SET.size()<<endl;
        if(SET.size()==n)
        {
            cout<<0<<endl;
            continue;
        }
        cout<<dfs(1,n)<<endl;
    }
    return 0;
}
